﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnterLevel : MonoBehaviour
{
    private string level_name;
    private int star_num;
    private int index;

    private void Awake()
    {
        //看前一关是否有星或者这是第一关
        index = transform.GetSiblingIndex();
        if (index == 0)
        {
            star_num = PlayerPrefs.GetInt(transform.name, 0);
            transform.Find("lock").gameObject.SetActive(false);
            transform.Find("unlock").gameObject.SetActive(true);
            for (int i = 0; i < star_num; i++)
            {
                transform.Find("unlock").GetChild(i).gameObject.SetActive(true);
            }
        }
        else
        {
            level_name = transform.parent.GetChild(index - 1).name;
            star_num = PlayerPrefs.GetInt(level_name, 0);
            if (star_num > 0)
            {
                transform.Find("lock").gameObject.SetActive(false);
                transform.Find("unlock").gameObject.SetActive(true);
                star_num = PlayerPrefs.GetInt(transform.name, 0);
                for (int i = 0;i < star_num;i++)
                {
                    transform.Find("unlock").GetChild(i).gameObject.SetActive(true);
                }
            }
        }
        
    }
}
